
#include "GLES1_Base.h"


/////////////////////////////////////
////          Struct part        ////
/////////////////////////////////////


GLES1_Base_Conf::GLES1_Base_Conf() : Draw_Base_Conf()
{
}



/////////////////////////////////////
////          Class part         ////
/////////////////////////////////////

/**
 *
 */
GLES1_Base::GLES1_Base() : Draw_Base()
{
    m_sGLES1_Base_Conf = new GLES1_Base_Conf();
    
    m_c2D_Manage = new TwoD_Manage();
    
    m_cTexCan = new TwoD_TexCan();
}

/**
 *
 */
int GLES1_Base::gles1_loadTexture()
{
    //LOGI("asset: %s * %d * %d\n", textBuf, _size, bufferSize);
    int _idents[] = {107};
    TwoD_TexCan* _imgCan = m_c2D_Manage->getTexLoader()->findByIdentifier(_idents, 0);
    
    m_cTexCan->putSome(_imgCan->m_arData, 1);
    
}


int GLES1_Base::gles1_drawTexture()
{
    
    glViewport(0, 0, 320, 480);
    static float grey, blue;
    grey = 0.0f;
    blue = 0.0f;
    
    const GLfloat vertices[] = {
                            //Vertices according to faces
                            0.0f, 0.0f, 0.0f,
                            0.4f, 0.0f, 0.0f,
                            0.0f, 0.5f, 0.0f,  
                            0.4f, 0.5f, 0.0f,
                            };
    
    const GLfloat texture[] = {    		
                            //Mapping coordinates for the vertices
                            0.0f, 0.0f,
                            1.0f, 0.0f,
                            0.0f, 1.0f,
                            1.0f, 1.0f,
			    };
                            
    /** The initial indices definition */	
    const GLbyte indices[] = {
                            //Faces definition
                            0,1,2, 1,2,3, 			//Face front	
                            };
    
    glClearColor(grey, blue, grey, 1.0f);
    glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //启用纹理功能
    glEnable(GL_TEXTURE_2D);
    //加载纹理贴图
    GLuint rectTexture;
    // 生成纹理
    glGenTextures(1, &rectTexture);
    // 绑定纹理
    glBindTexture(GL_TEXTURE_2D, rectTexture);
    // 位图存储规则 默认4
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    // Create Nearest Filtered Texture
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 56, 81, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_cTexCan->m_arData[0]->m_vData);
    
    //Point to our buffers
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    //Set the face rotation
    glFrontFace(GL_CCW);
    // scale
    glScalef(1.5f, 1.5f, 0.0f);
    // set light color
    //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texture);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
    
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    //glDrawArrays(GL_TRIANGLES, 0, 3);
}






